package com.wit.witmg.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wit.witmg.entity.TPatentfee;
import com.wit.witmg.mapper.TPatentfeeMapper;
import com.wit.witmg.service.ITPatentfeeService;
import com.wit.witmg.util.JsonResult;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @author bob
 * @since 2024-06-12
 */
@Service
public class TPatentfeeServiceImpl extends ServiceImpl<TPatentfeeMapper, TPatentfee> implements ITPatentfeeService {

    @Override
    public Object create(HttpServletRequest request, String json) {
        TPatentfee t=JSONObject.parseObject(json,TPatentfee.class);
        if(t.getId()>0){
            updateById(t);
        }else{
            save(t);
        }
        return JsonResult.success(t);
    }

    @Override
    public Object get(Integer zid, String payer, String dateS, String dateE) {
        QueryWrapper<TPatentfee> qw=new QueryWrapper<>();
        if(zid!=null){
            qw.eq("zid",zid);
        }
        if(payer!=null){
            qw.eq("payer",payer);
        }
        if(dateS!=null){
            qw.ge("date",dateS);
        }
        if(dateE!=null){
            qw.le("date",dateE);
        }
        return JsonResult.success(list(qw));
    }

    @Override
    public Object del(int id) {
        boolean bl= removeById(id);
        if(bl){
            return JsonResult.success();
        }
        return JsonResult.error("数据不存在");
    }
}
